package com.honeycomb.action.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.honeycomb.action.BaseAjaxAction;
import com.honeycomb.service.IArticleService;
import com.honeycomb.service.ITagService;
import com.honeycomb.service.IUserService;
import com.honeycomb.utils.SystemConstants;
import com.honeycomb.vo.ArticleinfoVO;
import com.honeycomb.vo.ResultDto;

public class AjaxQueryArticleListByTagsAction extends BaseAjaxAction {

	private IArticleService iArticleService;
	private IUserService iUserService;
	private ITagService iTagService;
	
	public IArticleService getiArticleService() {
		return iArticleService;
	}
	public void setiArticleService(IArticleService iArticleService) {
		this.iArticleService = iArticleService;
	}
	public IUserService getiUserService() {
		return iUserService;
	}
	public void setiUserService(IUserService iUserService) {
		this.iUserService = iUserService;
	}
	public ITagService getiTagService() {
		return iTagService;
	}
	public void setiTagService(ITagService iTagService) {
		this.iTagService = iTagService;
	}

	@Override
	protected JSONObject doRequest(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws Exception {
		logger.info("---------------------AjaxQueryArticleListByTagsAction------------------------");
		String tagArrStr = request.getParameter("tagArrStr");
		logger.info("tagArrStr:"+tagArrStr);
		String[] tagArr = tagArrStr.split("-");
		ResultDto<ArticleinfoVO> resultDto = null;
		List<ArticleinfoVO> articleInfoVOList = null;
		ArticleinfoVO articleInfoVO = null;
		
		JSONObject jo = new JSONObject();
		JSONArray ja = new JSONArray();
		JSONObject joo = null;
		
		try {
			resultDto = this.getiArticleService().doQueryArticleListByTags(tagArr);
			if(resultDto.isSuccess()) {
				articleInfoVOList = resultDto.getResultList();
				for(int i=0;i<articleInfoVOList.size();i++) {
					articleInfoVO = articleInfoVOList.get(i);
					joo = new JSONObject();
					joo.put("articleId", articleInfoVO.getArticleId());
					joo.put("articleTitle", articleInfoVO.getArticleTitle());
					joo.put("articleCreateDttmStr", articleInfoVO.getArticleCreateDttmStr());
					joo.put("articleSummary", articleInfoVO.getArticleSummary());
					joo.put("articleTag", articleInfoVO.getArticleTag());
					joo.put("userId", articleInfoVO.getUserId());
					joo.put("userNickname", articleInfoVO.getUserNickname());
					joo.put("userHeadImgUrl", articleInfoVO.getUserHeadImgUrl());
					ja.add(joo);
				}
				jo.put("data", ja);
				jo.put("result", SystemConstants.AJAX_SUCCESS);
			}else {
				jo.put("result", SystemConstants.AJAX_FAILED_ALERT);
			}
			return jo;
		} catch (Exception e) {
			e.printStackTrace();
			jo.put("result", SystemConstants.AJAX_FAILED_ALERT);
			return jo;
		}
	}

}


















